require(["vue", "ELEMENT"], function (vue, Element) {
  vue.use(Element);
  const control = {
    isOnline: true, // 是否线上坏境
    hostLocal: 'http://10.29.68.10:8203',
    hostOnline: 'http://120.77.202.109:8203'
  };
  const requestUrl = control.isOnline ? control.hostOnline : control.hostLocal;
  const page = {
    Request: function (type, url, data, loading, callback) {
      if (!url) {
        Element.Message.error('请求地址无效');
        return
      }
      url = requestUrl + url; // 拼接地址
      data = type == 'post' ? JSON.stringify(data) : data; // 请求参数
      return new Promise(function (resolve, reject) {
        $.ajax({
          type: type,
          url: url,
          data: data,
          dataType: "json",
          contentType: 'application/json',
          success:function(res) {
            if (res.code == 200) {
              resolve(res);
            } else {
              reject(res);
            }
          },
          error:function(err) {
            Element.Message.error('请求失败');
            reject(err);
          }
        });
      });
    },
    getRecordDate: function (date, type) {
      var time = new Date(date);
      // 提取年月日
      var Y = time.getFullYear();
      var M = time.getMonth() + 1;
      var D = time.getDate();
      // 提取星期
      var W = time.getDay();
      // 提取时分秒
      var h = time.getHours();
      var m = time.getMinutes();
      var s = time.getSeconds();
      // 不足10的填充0
      M = M >= 10 ? M : "0" + M;
      D = D >= 10 ? D : "0" + D;
      h = h >= 10 ? h : "0" + h;
      m = m >= 10 ? m : "0" + m;
      s = s >= 10 ? s : "0" + s;
      // 输出时间格式
      if (type == 1) {
        var weekDay = ["一", "二", "三", "四", "五", "六", "天"];
        return Y + '-' + M + '-' + D + "  星期" + weekDay[W] + " " + h + " : " + m + " : " + s; // YYYY/MM/DD  W  hh:mm:ss
      } else {
        if (type == 2) {
          return Y + '-' + M + '-' + D + " " + h + ":" + m + ":" + s; // YYYY/MM/DD  hh:mm:ss
        } else if (type == 3) {
          return Y + '-' + M; // YYYY/MM
        } else if (type == 4) {
          return Y + '.' + M + '.' + D; // YYYY/MM
        } else {
          return Y + '-' + M + '-' + D; // YYYY/MM/DD
        }
      }
    },
    getSearchDataFun: function () {
      var str = location.search;
      str = str.slice(1).split('&');
      var json = {};
      for (var i = 0; i < str.length; i++) {
        var a = str[i].split('=');
        json[a[0]] = decodeURI(a[1]);
      }
      return json;
    },
    // api配置
    apiUrl: {
      'getIndexInfo': '/dfyzapi/website/index', // 获取首页信息
      'getNews': '/dfyzapi/website/action', // 获取新闻
      'getNewsInfo': '/dfyzapi/website/publishMassages', // 获取新闻详情
      'getTagsList': '/dfyzapi/website/queryTag', // 获取标签库
      'getTagsNews': '/dfyzapi/website/queryTagOne', // 获取标签库对应的新闻
    }
  }
  $("body").data("config", page);
  // 图片懒加载
  // console.log($("#app img"))
  // $("#app img").lazyload({
  //     effect : "fadeIn"
  // });
  (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?cc3a5ecb7a82929c3bc2b135c11c7659";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
  })();
})
